package com.limbo.showapp.presenter;

import com.limbo.showapp.base.BaseModel;
import com.limbo.showapp.base.BasePresenter;
import com.limbo.showapp.model.DownloadModel;
import com.limbo.showapp.rxHttp.download.DownloadListener;
import com.limbo.showapp.view.IDownloadView;

/**
 * Created by wangqi on 2018/9/7.
 */

public class DownloadPresenter extends BasePresenter<IDownloadView,DownloadModel> {

    @Override
    protected DownloadModel getModel() {
        return new DownloadModel();
    }

    public void down(String url, String filePath) {
        mModel.down(url, filePath, new DownloadListener() {
            @Override
            public void onStartDownload() {
                if (getView() != null)
                    getView().onDownStart();
            }

            @Override
            public void onProgress(int progress) {
                //子线程中
                //需要切换线程
                if (getView() != null)
                    getView().onDownProgress(progress);
            }

            @Override
            public void onFinishDownload() {
                if (getView() != null)
                    getView().onDownFinish();
            }

            @Override
            public void onFail(String errorInfo) {
                if (getView() != null)
                    getView().onDownFail(errorInfo);
            }
        });
    }
}
